<template>
  <div class="login-container">
    <div class="background-image"></div>
    <div class="system-header">
      <img src="../assets/logo.png" alt="实验室logo" class="logo">
      <h2 class="system-title">实验室器材管理系统</h2>
    </div>
    <div class="login-form-container">
      <form @submit.prevent="handleSubmit" class="login-form">
        <h1>登录</h1>
        <div class="form-group">
          <label for="username">账号</label>
          <input
            id="username"
            v-model="username"
            type="text"
            required
            placeholder="请输入账号"
          >
        </div>
        <div class="form-group">
          <label for="password">密码</label>
          <input
            id="password"
            v-model="password"
            type="password"
            required
            placeholder="请输入密码"
          >
        </div>
        <div class="form-group checkbox">
          <input
            id="isAdmin"
            v-model="isAdmin"
            type="checkbox"
          >
          <label for="isAdmin">管理员登录</label>
        </div>
        <button type="submit" :disabled="!isFormValid">登录</button>
        <div class="register-link">
          还没有账号？<router-link to="/register">立即注册</router-link>
        </div>
      </form>
    </div>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import { useRouter } from 'vue-router';

const router = useRouter();

const username = ref('')
const password = ref('')
const isAdmin = ref(false)

const isFormValid = computed(() => {
  return username.value.trim() !== '' && password.value.trim() !== ''
})

const handleSubmit = () => {
  if (isFormValid.value) {
    console.log('登录信息：', {
      username: username.value,
      password: password.value,
      isAdmin: isAdmin.value
    })
  }
}
</script>

<style scoped>
.background-image {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: url('../assets/test.jpg');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  width: 100vw;
  height: 100vh;
  filter: brightness(0.7);
  z-index: 0;
}

.system-header {
  position: fixed;
  top: 20px;
  left: 20px;
  display: flex;
  align-items: center;
  z-index: 2;
}

.logo {
  width: 50px;
  height: 50px;
  margin-right: 15px;
}

.system-title {
  color: white;
  font-size: 24px;
  margin: 0;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.login-container {
  display: flex;
  justify-content: flex-end; /* 将登录框推到右侧 */
  align-items: center;
  min-height: 90vh;
  margin-left: 45vh;
  position: relative;
  width: 100%;
}

.login-form-container {
  background-color: rgba(255, 255, 255, 0.9);
  padding: 3rem;
  border-radius: 8px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  width: 500px;
  height: 500px;
  margin-right: 5%; /* 调整右侧的间距 */
  z-index: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.login-form {
  display: flex;
  flex-direction: column;
}

h1 {
  text-align: center;
  margin-bottom: 2rem;
  color: #333;
  font-size: 28px;
}

.form-group {
  margin-bottom: 1.5rem;
}

label {
  display: block;
  margin-bottom: 0.5rem;
  color: #666;
  font-size: 16px;
}

input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 16px;
}

.checkbox {
  display: flex;
  align-items: center;
}

.checkbox input {
  margin-right: 0.5rem;
  width: 18px;
  height: 18px;
}

button {
  width: 100%;
  padding: 1rem;
  background-color: #4CAF50;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 18px;
  margin-top: 1rem;
}

button:disabled {
  background-color: #9E9E9E;
  cursor: not-allowed;
}

.register-link {
  text-align: center;
  margin-top: 1.5rem;
  font-size: 16px;
}

a {
  color: #2196F3;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}
</style>
